package com.axdoc.walletbiz.record.mq.service.impl;

import java.math.BigDecimal;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.axdoc.walletbiz.record.mq.message.DkFailureMessage;
import com.axdoc.walletbiz.record.mq.message.Message;
import com.axdoc.walletbiz.record.mq.service.MsgService;
import com.axdoc.walletbiz.record.service.RecordService;

/**
 * 打款成功消息
 * 
 * @author sunzhaoli
 *
 */
@Component("dkFailureService")
public class DkFailureServiceImpl implements MsgService {
	public static Logger logger = LoggerFactory.getLogger("listen_message");

	@Autowired
	private RecordService recordService;

	@Override
	public void handle(Message msg) {
		try {
			DkFailureMessage message = (DkFailureMessage) msg;
			logger.info("[处理打款失败消息,req,msg:" + message + " ]");
			String biz_no = message.getData().get("withdrawsId").toString();
			String doc_id = message.getData().get("docId").toString();
			BigDecimal balance = new BigDecimal(message.getData().get("balance").toString());
			Long biz_time = StringUtils.isEmpty(message.getData().get("bizTime").toString())
					? System.currentTimeMillis() : Long.valueOf(message.getData().get("bizTime").toString());
			// 开始记账
			recordService.dkFailure(biz_no, doc_id, balance.intValue(),biz_time, msg.getId());
		} catch (Exception e) {
			logger.error("[处理打款失败消息异常,error,msg:" + msg, e);
		}
	}

}
